﻿// =================================================================== 
// 项目说明
//====================================================================
// sushee。@Copy Right 2019
// 文件： SeatNumber.cs
// 项目名称：斑马车务
// 创建时间：2020/5/19
// 负责人：sushee
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using Dapper.Extensions;
using System.Linq.Expressions;
using CRM.Infrastructure.Entity;
using CRM.Infrastructure.Repository;
namespace CRM.Infrastructure.Service
{
	
	/// <summary>
	///
	/// </summary>
	public class SeatNumberService
	{
         protected SeatNumberRepository repository;
         
         public  SeatNumberService(){
           repository = new SeatNumberRepository("CarServerConnectionString");         
         }
         
        #region 增删改查

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(SeatNumber entity) { return repository.Insert(entity); }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(List<SeatNumber> entitys) { return repository.Insert(entitys); }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Update(SeatNumber entity) { return repository.Update(entity); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Delete(SeatNumber entity) { return repository.Delete(entity); }

        /// <summary>
        /// 删除所有
        /// </summary>
        /// <returns></returns>
        public bool DeleteAll() { return repository.DeleteAll(); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public bool Delete(int primaryKey) { return repository.Delete(primaryKey); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public SeatNumber SingleOrDefault(object primaryKey) { return repository.SingleOrDefault(primaryKey); }

       
        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public SeatNumber Single(object primaryKey) { return repository.Single(primaryKey); }

        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<SeatNumber> QueryAll()
        {
            return repository.QueryAll();
        }
        
        #endregion
        
        #region 单表查询帮助方法
        /// <summary>
        /// 根据谓词表达式获取一个对象，如果没有获取到对象，则返回null
        /// </summary>
        /// <param name="predicate">谓词表达式</param>
        /// <param name="useCache">是否使用缓存</param>
        /// <returns></returns>
        public SeatNumber  QuerySingle(Expression<Func<SeatNumber , bool>> predicate, bool useCache = false)
        {
            return repository.QuerySingle(predicate);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="M"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="useCache"></param>
        /// <returns></returns>
        public M QuerySingle<M>(Expression<Func<M, bool>> predicate, bool useCache = false) where M : class
        {
            return repository.QuerySingle<M>(predicate,useCache);
        }
        /// <summary>
        /// 根据谓词表达式获取一个对象列表，如果没有获取到对象，则返回一个空列表
        /// </summary>
        /// <param name="predicate">谓词表达式</param>
        /// <param name="useCache">是否使用缓存</param>
        /// <returns></returns>
        public List<SeatNumber> QueryList(Expression<Func<SeatNumber , bool>> predicate, bool useCache = false)
        {
            return repository.QueryList(predicate, useCache);
        }
        /// <summary>
        /// 根据谓词表达式获取一个对象列表，如果没有获取到对象，则返回一个空列表
        /// </summary>
        /// <typeparam name="M"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="useCache"></param>
        /// <returns></returns>
        public List<M> QueryList<M>(Expression<Func<M, bool>> predicate, bool useCache = false) where M : class
        {
            return repository.QueryList<M>(predicate, useCache);
        }

        #endregion
	}
	
}